package com.springboot.controller;

import com.springboot.entity.UserInfoEntity;
import com.springboot.utils.SpringUtils;
import com.springboot.service.UserInfoService;
import com.springboot.service.anno.DiyScheduled;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

@Controller
public class IndexCtrl {

    @RequestMapping("admin/login")
//    @Transactional
    public String login(Model model) {

        System.out.println("开始");
        /*List<UserInfoEntity> a1 = userInfoService.selectList();
        List<UserInfoEntity> a2 = userInfoService.selectList();
        System.out.println(a1.equals(a2));
        System.out.println("結束");


        userInfoService.updateUserInfo(11, "111");*/
        UserInfoEntity b1 = userInfoService.selectOne("111");
        UserInfoEntity b2 = userInfoService.selectOne("111");
       /* System.out.println(b1 == b2);//true
        List<UserInfoEntity> a3 = userInfoService.selectList();
        System.out.println(a1 == a3);//true
        List<UserInfoEntity> a4 = userInfoService.selectList();
        List<UserInfoEntity> a5 = userInfoService.selectList();
        System.out.println(a1 == a2);//true
        System.out.println(a2 == a4);//false
        System.out.println(a4 == a5);//true

        a1 = a1.stream().filter(userInfoEntity -> userInfoEntity.getAge() != 20).collect(Collectors.toList());
        int timestamp = (int) (System.currentTimeMillis() / 1000);*/
        List<UserInfoEntity> list = new ArrayList<>();
        list.add(b1);
        //userInfoService.updateUserInfo(timestamp,"2020-06-07");
        model.addAttribute("userInfoList", list);
        return "login";
//    @Transactional(rollbackFor = Exception.class)
    }

    @Autowired
    private UserInfoService userInfoService;
            /*Object testTask = SpringUtils.getBean("testTask");
        Method[] declaredMethods = testTask.getClass().getDeclaredMethods();
        for (Method declaredMethod : declaredMethods) {
            if (declaredMethod.isAnnotationPresent(DiyScheduled.class)) {
                declaredMethod.setAccessible(true);
                try {
                    declaredMethod.invoke(testTask);
                } catch (IllegalAccessException | InvocationTargetException e) {
                    e.printStackTrace();
                }
            }
        }*/

}
